﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;

namespace BaseProject.Infrastructure.Helpers
{
    public static class UtilHelper
    {
        public static string GetRandom()
        {
            Random rad = new Random();
            int value = rad.Next(1000, 10000);
            return value.ToString();
        }

        public static string GetRandomPassword()
        {
            Random rad = new Random();
            var uppers = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            var lowers = "abcdefghijklmnopqrstuvwxyz";
            return uppers[rad.Next(0, uppers.Length)].ToString() + lowers[rad.Next(0, lowers.Length)].ToString() + rad.Next(1000, 10000);
        }

        public static string Md5(string value)
        {
            byte[] bytes;
            using (var md5 = MD5.Create())
            {
                bytes = md5.ComputeHash(Encoding.UTF8.GetBytes(value));
            }
            var result = new StringBuilder();
            foreach (byte t in bytes)
            {
                result.Append(t.ToString("X2"));
            }
            return result.ToString();
        }
    }
}